<template>
	<div>
		<div class="div_one">
			<span>欢迎:</span>
			<span class="name">{{names}}</span>
			<span>{{time}}</span>
		</div>
		<div class="div_two">
			<div class="div_three">打卡签到</div>
			<hr />
			<el-button  v-show="istrue" type="primary" round style="margin-left: 10px;margin-top: 10px;" @click="up">上班打卡</el-button>
			<el-button  v-show="istrue" type="info" round @click="down">下班打卡</el-button>
		</div>
	</div>
	
</template>

<script>
	export default{
		name: 'login',
		data(){
			return{
				uid:'',
				names:'',
				time:'',
				show:false, 
				//是否是咨询师
			    istrue:false
			}
		},
		created(){
			this.getRolesList()
			// this.getIstrue()
		},
		methods:{
			getRolesList() {
				let s = parseInt(window.sessionStorage.getItem('token'));
				console.log(s);
				let _this = this;
				this.$axios.post('/api/api/Staffclock/GetRole', {
					Id: s
				}).then(function(res) {
					console.log(res.data);
					if (res.data.code == 0) {
						_this.names=res.data.name;						
						_this.time = res.data.time;						
						if(_this.names=="咨询师"){
							_this.istrue=true
							
						}else{
							_this.istrue=false
						}
					} else {
						
					}
				})
			},		
			async up(){
				const { data: res } = await this.$http.get('/api/api/Staffclock/up', {
					params: {
					 UserId:parseInt(window.sessionStorage.getItem('token')),
					 time:this.gettime()
					}
				});
				if (res.code !== 0) return this.$message.error(res.msg);
				  this.$message.success(res.msg);
			},
			async down(){
				const { data: res } = await this.$http.get('/api/api/Staffclock/down', {
					params: {
					 UserId:parseInt(window.sessionStorage.getItem('token')),
					 time:this.gettime()
					}
				});
				if (res.code !== 0) return this.$message.error(res.msg);
				  this.$message.success(res.msg);
			},
			gettime(){
						  var nowDate = new Date();
						       let date = {
						         year: nowDate.getFullYear(),
						         month: nowDate.getMonth() + 1,
						  					  day:nowDate.getDay(),
						  					  h:nowDate.getHours(),
						  					  s:nowDate.getMinutes(),
						  					  ss:nowDate.getSeconds()
						       };
						       let systemDate = date.year + "年" + date.month + "月"+date.h+"时"+date.s+"分"+date.ss+"秒";
							   return systemDate
			}
		}
	} 
</script>

<style Lang="less" scoped>
	.div_one{
		height: 40px;
		width: 100%;
		background-color: white;
	    line-height: 40px;
	}
	.div_one span{
		padding-left: 20px;
	}
	.div_two{
		margin-top: 30px;
		height: 120px;
		width: 100%;
	    /* background-color: #EAEDF1; */
		background-color: white;
	}
	.div_three{
		padding-left: 20px;
		padding-top: 10px;
		font-size: 16px;
	}
	hr{
		border: 1px solid #EAEDF1;
		width: 97%;
	}
	.name{
		color: rosybrown;
	}
</style>
